package com.joker.web.controller.orange;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.joker.common.annotation.RepeatSubmit;
import com.joker.common.annotation.Log;
import com.joker.common.core.controller.BaseController;
import com.joker.common.core.domain.PageQuery;
import com.joker.common.core.domain.R;
import com.joker.common.core.validate.AddGroup;
import com.joker.common.core.validate.EditGroup;
import com.joker.common.enums.BusinessType;
import com.joker.common.utils.poi.ExcelUtil;
import com.joker.orange.domain.vo.DiamondConsumeRecordVo;
import com.joker.orange.domain.bo.DiamondConsumeRecordBo;
import com.joker.orange.service.IDiamondConsumeRecordService;
import com.joker.common.core.page.TableDataInfo;

/**
 * 充值记录
 *
 * @author Joker
 * @date 2024-06-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/consumer/recharge")
public class DiamondConsumeRecordController extends BaseController {

    private final IDiamondConsumeRecordService iDiamondConsumeRecordService;

    /**
     * 查询充值记录列表
     */
    @SaCheckPermission("consumer:recharge:list")
    @GetMapping("/list")
    public TableDataInfo<DiamondConsumeRecordVo> list(DiamondConsumeRecordBo bo, PageQuery pageQuery) {
        return iDiamondConsumeRecordService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出充值记录列表
     */
    @SaCheckPermission("consumer:recharge:export")
    @Log(title = "充值记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DiamondConsumeRecordBo bo, HttpServletResponse response) {
        List<DiamondConsumeRecordVo> list = iDiamondConsumeRecordService.queryList(bo);
        ExcelUtil.exportExcel(list, "充值记录", DiamondConsumeRecordVo.class, response);
    }

    /**
     * 获取充值记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("consumer:recharge:query")
    @GetMapping("/{id}")
    public R<DiamondConsumeRecordVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iDiamondConsumeRecordService.queryById(id));
    }

    /**
     * 新增充值记录
     */
    @SaCheckPermission("consumer:recharge:add")
    @Log(title = "充值记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DiamondConsumeRecordBo bo) {
        return toAjax(iDiamondConsumeRecordService.insertByBo(bo));
    }

    /**
     * 修改充值记录
     */
    @SaCheckPermission("consumer:recharge:edit")
    @Log(title = "充值记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DiamondConsumeRecordBo bo) {
        return toAjax(iDiamondConsumeRecordService.updateByBo(bo));
    }

    /**
     * 删除充值记录
     *
     * @param ids 主键串
     */
    @SaCheckPermission("consumer:recharge:remove")
    @Log(title = "充值记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iDiamondConsumeRecordService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
